import HttpRequest from 'lib-plugins/axios';
import store from '../store'
import router from '../router'
const httpRequest = new HttpRequest({
    proxyUrl: process.env.VUE_APP_PROXY_URL,
    baseURL: process.env.VUE_APP_BASE_URL,
    token: () => {
        return store.state.common.token ? store.state.common.token : ''
    },
    notAuthUrls: [],
    callBackNoAuth: () => {
        router.push('/login')
    },
    startLoading: () => {
        store.commit('setCommonStore', {
            showPageLoading: true
        })
    },
    closeLoading: () => {
        store.commit('setCommonStore', {
            showPageLoading: false
        })
    },
    callBackError: null
})

export const get = (url: string, params?: any) => {
    return httpRequest.baseRequest('GET', url, params)
}

export const post = (url: string, params?: any) => {
    return httpRequest.baseRequest('POST', url, params)
}

export const postForm = (url: string, params?: any) => {
    return httpRequest.baseRequest('POST', url, params, true)
}

export default httpRequest